clear all
clc
% n = input('number of classes: ');
muc=0.033;
C=30;
Lambdac= [5];
T=2;
n=ceil(((Lambdac - muc)*T))/(T*C*muc-1);
% Pv=decreasingdist(n);
Pv=Gaussiandist(n);
Pc=Gaussiandist(n);


% Lambdac=0:0.1:20;
R=zeros(length(Lambdac),1);
R1=zeros(length(Lambdac),1);
% Waitings=zeros(length(Lambdac),1);
Waitings1=zeros(length(Lambdac),1);
lb=zeros(n,1);
ub=ones(n,1);
ub(n+1)=inf;
b1=zeros(n+2,1);


% T=5:0.1:20;
% R=zeros(length(T),1);
% T=5:0.1:20;
% R=zeros(length(T),1);
%  options = optimoptions('fmincon','TolCon',0);
%  options = psoptimset('TolCon',0,'TolMesh',0);
 for j=1:length(Lambdac)
lb(n+1)=Lambdac(j) + n*(1/T) ;
for i=1:n
    b1(i)= Lambdac(j)*Pc(i) + (1/T) ;
end
b1(n+1)= -C*n*muc;
b1(n+2)= -(muc);
cond = @(x)parameterfun(x,n,Pv,b1);
obj=@(x)x(n+1);
% x0 = ones(1,n+1);
x0 = zeros(1,n);
x0(n+1)= Lambdac(j)+n*(1/T);
[x,fval,exitflag,output,lambda] = fmincon(obj,x0,[],[],[],[],lb,ub,cond);
%[x,fval,exitflag,output] = patternsearch(obj,x0,[],[],[],[],lb,ub,cond);
R(j)= x(n+1);
 end
[cout,ceqout] = parameterfun(x,n,Pv,b1);
Waitings=[];
for i=1:n
   Waitings(i)=1/(-cout(i)+(1/T)) ;
end

% plot(Lambdac,R);
% plot(Lambdac,Waitings);

x1= ones(1,n);
x1(2)=(Pv(1)*x(1)/Pv(2)) - (((x(n+1)*Pv(1))-(Pc(1)*Lambdac(1))-(1/T))/(x(n+1)*Pv(2)));
x1(3)=(Pv(2)*x(2)/Pv(3)) - (((x(n+1)*Pv(2))-(Pc(2)*Lambdac(1))-(1/T))/(x(n+1)*Pv(3)));
